package com.dragon.im.util;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

public class Result {
	/**
	 * 登录状态,0表示游客,1表示登录成功,-1表示登录失效
	 */
	private int code;
	/**
	 * 要传输的数据
	 */
	private Object data;
	/**
	 * 携带信息
	 */
	private String msg;

	public Result() {
		super();
	}

	public Result(int code, Object data, String msg) {
		super();
		this.code = code;
		this.data = data;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

	public void send(HttpServletResponse response) throws IOException {
		// 
		response.setContentType("application/json");
		// 
		response.getWriter().append(this.toString());
	}
}
